<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>src/ux/Ux.Normalize.js - Zero UI Doc</title>
    <meta name="description" content="Zero UI前端文档工具">
    <link rel="stylesheet" href="http://yui.yahooapis.com/3.9.1/build/cssgrids/cssgrids-min.css">
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
    <link rel="stylesheet" href="../assets/css/custom.css">
    <link rel="stylesheet" href="../assets/vendor/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="../assets/vendor/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../assets/css/theme.css">
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,500,600,700" rel="stylesheet" type="text/css">
    <link rel="shortcut icon" type="image/png" href="../assets/img/favicon.png">
    
</head>
<body>
    <nav class="navbar navbar-default">
      <div class="container-fluid">
        <div class="navbar-header">
          <a href="../" class="navbar-brand">
            <img src="../assets/img/mdeditor-logo.png" alt="">
            <span>API Docs</span>
          </a>
        </div>

        <div class="collapse navbar-collapse" id="nav">
          <ul class="nav navbar-nav navbar-right">
            <li><a href="https://github.com/silentbalanceyh/vertx-ui.git" class="fa fa-github github"></a></li>
          </ul>
        </div>
      </div>
    </nav>
    <div id="main-wrapper" class="row">
        <div id="content-wrapper">
            <ol class="panel-group" id="sidebar" role="tablist" aria-multiselectable="true">
                <li class="panel panel-default">
                    <div class="panel-heading" role="tab" id="sidebar-search-heading">
                        <h4 class="panel-title">
                      <a role="button" data-toggle="collapse" href="#sidebar-search" aria-expanded="true" aria-controls="collapseOne">
                        Search
                      </a>
                    </h4>
                    </div>
                    <div id="sidebar-search" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="sidebar-search-heading">
                        <div class="panel-body">
                            <div id="api-tabview-filter">
                                <input type="search" id="api-filter" placeholder="Search...">
                            </div>
                        </div>
                    </div>
                </li>
                    <li class="panel panel-default">
                        <div class="panel-heading" role="tab" id="sidebar-version-heading">
                            <h4 class="panel-title">
                                <a role="button" href="https://github.com/silentbalanceyh/vertx-ui.git/commits/0" target="_blank">
                                  Tag: 0.1.0
                                </a>
                            </h4>
                        </div>
                    </li>
                <li class="panel panel-default">
                    <div class="panel-heading" role="tab" id="sidebar-modules-heading">
                        <h4 class="panel-title">
                    <a role="button" data-toggle="collapse" href="#sidebar-modules" aria-expanded="true" aria-controls="collapseOne">
                      Modules
                    </a>
                  </h4>
                    </div>
                    <div id="sidebar-modules" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="sidebar-modules-heading">
                        <div class="panel-body">
                                <ol>
                                        <li>
                                            <a href="../modules/Ux.html">Ux</a>
                                        </li>
                                </ol>
                        </div>
                    </div>
                </li>
            
                <li class="panel panel-default">
                    <div class="panel-heading" role="tab" id="sidebar-classes-heading">
                        <h4 class="panel-title">
                      <a role="button" data-toggle="collapse" href="#sidebar-classes" aria-expanded="true" aria-controls="collapseOne">
                        Classes
                      </a>
                    </h4>
                    </div>
                    <div id="sidebar-classes" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="sidebar-classes-heading">
                        <div class="panel-body">
                            <ol>
                                    <li>
                                        <a href="../classes/Action.html">Action</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Ajax.html">Ajax</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Attribute.html">Attribute</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Column.html">Column</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Debug.html">Debug</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Depend.html">Depend</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Dialog.html">Dialog</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Encrypt.html">Encrypt</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Env.html">Env</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Expr.html">Expr</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Field.html">Field</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Format.html">Format</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Global.html">Global</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Hoc.html">Hoc</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Html.html">Html</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Icon.html">Icon</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Jsx.html">Jsx</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Log.html">Log</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Normalize.html">Normalize</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Op.html">Op</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Option.html">Option</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Param.html">Param</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Prop.html">Prop</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Random.html">Random</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Redux.html">Redux</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Sorter.html">Sorter</a>
                                    </li>
                                    <li>
                                        <a href="../classes/State.html">State</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Store.html">Store</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Type.html">Type</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Validator.html">Validator</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Value.html">Value</a>
                                    </li>
                            </ol>
                        </div>
                    </div>
                </li>
            </ol>
            <div class="content-container">
                <div class="apidocs">
                    <div id="docs-main">
                        <div class="content">
<div class="page-header">
    <h1><i class="fa fa-file-code-o" aria-hidden="true"></i>  File</h1>
</div>

<div class="file">
    <pre class="prettyprint linenums">
import Dg from &#x27;./Ux.Debug&#x27;
import Validator from &#x27;./Ux.Validator&#x27;
import Type from &#x27;./Ux.Type&#x27;;
import Html from &#x27;./Ux.Html&#x27;;

const limitNumber = (length) =&gt; value =&gt; {
    if (value) {
        // 整数限制
        value = value.toString();
        if (1 === value.length) {
            value = value.replace(/[^1-9]/g, &quot;&quot;);
        } else {
            value = value.replace(/\D/g, &quot;&quot;);
        }
        // 长度限制
        if (0 &lt; length) {
            if (length &lt; value.length) {
                value = value.substring(0, length);
            }
        }
    }
    return value;
};
const limitDecimal = (length, scale = 2) =&gt; value =&gt; {
    if (value) {
        // 2.正数输入限制
        value = value.toString();
        value = value.replace(/[^\d.]/g, &quot;&quot;); //清除“数字”和“.”以外的字符
        value = value.replace(/\.{2,}/g, &quot;.&quot;); //只保留第一个. 清除多余的
        value = value
            .replace(&quot;.&quot;, &quot;$#$&quot;)
            .replace(/\./g, &quot;&quot;)
            .replace(&quot;$#$&quot;, &quot;.&quot;);
        const scaleReg = new RegExp(&#x60;(\\-)*(\\d+)\\.(\\d{${scale}}).&#x60;);
        value = value.replace(scaleReg, &#x60;$1$2.$3&#x60;); //只能输入两个小数
        // 3.长度输入限制
        if (length &lt; value.length) {
            value = value.substring(0, length);
        }
        return value;
    }
    return value;
};
const normalizer = {
    decimal: limitDecimal,
    number: limitNumber
};
const mountNormalizer = (reference, item = {}) =&gt; {
    if (item.optionConfig &amp;&amp; item.optionConfig.normalize) {
        const expr = item.optionConfig.normalize;
        if (expr) {
            const segments = expr.toString().split(&quot;,&quot;);
            if (1 &lt; segments.length) {
                // 读取类型
                const type = segments[0];
                const executor = normalizer[type];
                if (executor) {
                    // 参数准备
                    const args = [];
                    for (let idx = 1; idx &lt; segments.length; idx++) {
                        args.push(segments[idx]);
                    }
                    // 函数调用
                    const jFun = executor.apply(null, args);
                    if (jFun) {
                        item.optionConfig.normalize = jFun;
                    }
                }
            }
        }
    }
};
const mountErrorFocus = (reference, item) =&gt; {
    if (item.field) {
        if (!item.optionJsx) item.optionJsx = {};
        // onFocus
        item.optionJsx.onFocus = Html.htmlErrorFocus(item);
        // onBlur
        item.optionJsx.onBlur = Html.htmlErrorBlur(item);
    }
};
/**
 * 处理当前Form中的input控件专用信息
 * @method extractForm
 * @param {ReactComponent} reference React对应组件引用
 * @return {*}
 */
const extractForm = (reference = {}) =&gt; {
    const {$hoc} = reference.state;
    Dg.ensureNotNull($hoc);
    const form = $hoc._(&quot;form&quot;);
    Dg.ensureNotNull(form);
    if (form) {
        form.ui = Type.itMatrix(form.ui, (item) =&gt; Validator.mountValidator(reference, item));
        form.ui = Type.itMatrix(form.ui, (item) =&gt; mountNormalizer(reference, item));
        form.ui = Type.itMatrix(form.ui, (item) =&gt; mountErrorFocus(reference, item));
        return form.ui;
    } else {
        return [];
    }
};
/**
 * 处理当前Form中的button或操作按钮配置信息
 * @method extractOp
 * @param {ReactComponent} reference React对应组件引用
 * @return {any}
 */
const extractOp = (reference = {}) =&gt; {
    const {$hoc} = reference.state;
    Dg.ensureNotNull($hoc);
    const form = $hoc._(&quot;form&quot;);
    Dg.ensureNotNull(form);
    return form ? form.op : [];
};
/**
 * 处理type = hidden类型的配置信息
 * @method extractHidden
 * @param {ReactComponent} reference React对应组件引用
 * @return {{}}
 */
const extractHidden = (reference = {}) =&gt; {
    const {$hoc} = reference.state;
    Dg.ensureNotNull($hoc);
    const form = $hoc._(&quot;form&quot;);
    Dg.ensureNotNull(form);
    const hidden = (form &amp;&amp; form.hidden) ? form.hidden : {};
    if (!hidden.hasOwnProperty(&#x27;opVisible&#x27;)) {
        hidden.opVisible = true;
    }
    if (!hidden.hasOwnProperty(&#x27;inputs&#x27;)) {
        hidden.inputs = [];
    }
    return hidden;
};
/**
 * @class Normalize
 * @description 专用Form配置处理类，它的方法大部分都是内部使用
 */
export default {
    // 读取Form配置专用方法
    extractForm,
    extractHidden,
    extractOp
}

    </pre>
</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="../assets/vendor/prettify/prettify-min.js"></script>
    <script>prettyPrint();</script>
    <script src="../assets/vendor/jquery/jquery.min.js"></script>
    <script src="../assets/vendor/jquery-ui/jquery-ui.min.js"></script>
    <script src="../assets/vendor/bootstrap/js/bootstrap.js"></script>
    <script src="../assets/vendor/github-slugger/slugger.js"></script>
    <script src="../assets/js/yuidoc-bootstrap.js"></script>
</body>
</html>
